<?php
include_once("_common.php");
include_once($g4['path']."/head.sub.php");

$default_charset = '';
if (preg_match("/^utf/i", $g4['charset']))
    $default_charset = "default charset=utf8;";

$sql = "create table if not exists {$mw_cash['cash_table']} (
mb_id varchar(20) not null,
mb_cash decimal(11,2) not null,
primary key  (mb_id)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['account_table']} (
ac_id int(11) not null auto_increment,
mb_id varchar(20) not null,
ac_name varchar(20) not null,
ac_hp varchar(20) not null,
ac_payment int(11) not null,
ac_paydate date not null,
ac_datetime datetime not null,
ac_memo text not null,
ac_admin_memo text not null,
ac_to_cash char(1) not null,
ac_status varchar(20) not null,
ac_tax char(1) not null,
primary key  (ac_id),
key mb_id (mb_id),
key ac_name (ac_name)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['cash_config_table']} (
cf_id char(1) not null default '1',
cf_cash_name varchar(50) not null,
cf_cash_unit varchar(50) not null,
cf_cash_price int(11) not null,
cf_charge_min int(11) not null,
cf_card_min int(11) not null,
cf_tax char(1) not null,
cf_possible_day int(11) not null,
cf_point char(1) not null,
cf_card char(1) not null,
cf_hp char(1) not null,
cf_account char(1) not null,
cf_bank char(1) not null,
cf_sms char(1) not null,
cf_icode_id varchar(20) not null,
cf_icode_pw varchar(20) not null,
cf_sms_content varchar(255) not null,
cf_sms_return varchar(20) not null,
primary key  (cf_id)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['cash_list_table']} (
cl_id int(11) not null auto_increment,
mb_id varchar(20) not null,
rel_table varchar(20) not null,
rel_id varchar(20) not null,
rel_mb_id varchar(20) not null,
cl_domain varchar(255) not null,
cl_cash_price int(11) not null,
cl_cash decimal(11,2) not null,
cl_tax char(1) not null,
cl_tax_voucher tinyint not null,
cl_voucher tinyint not null,
cl_content varchar(255) not null,
cl_payment decimal(11,2) not null,
cl_paytype varchar(20) not null,
cl_paylog text not null,
cl_admin_memo text not null,
cl_datetime datetime not null,
cl_ip varchar(20) not null,
cl_agent varchar(255) not null,
cl_status char(1) not null,
primary key  (cl_id),
key mb_id (mb_id,cl_datetime,cl_payment),
key cl_rel_table (rel_table,rel_id,rel_mb_id)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['membership_table']} (
ms_id int(11) not null auto_increment,
ms_name varchar(255) not null,
ms_status char(1) not null,
primary key  (ms_id)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['membership_board_table']} (
mp_id int(11) not null auto_increment,
ms_id int(11) not null,
bo_table varchar(20) not null,
mp_list char(1) not null,
mp_view char(1) not null,
mp_down char(1) not null,
mp_write char(1) not null,
mp_comment char(1) not null,
primary key  (mp_id),
key ms_id (ms_id,bo_table)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['membership_item_table']} (
mi_id int(11) not null auto_increment,
ms_id int(11) not null,
mi_cash int(11) not null,
mi_day int(11) not null,
mi_datetime datetime not null,
primary key  (mi_id),
key ms_id (ms_id)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['membership_log_table']} (
ml_id int(11) not null auto_increment,
cl_id int(11) not null,
ms_id int(11) not null,
mb_id varchar(20) not null,
ml_cash int(11) not null,
ml_day int(11) not null,
ml_sdate datetime not null,
ml_edate datetime not null,
ml_datetime datetime not null,
primary key  (ml_id),
key ms_id (ms_id,mb_id,ml_sdate,ml_edate)
) $default_charset";
$qry = sql_query($sql);

$sql = "create table if not exists {$mw_cash['grade_table']} (
gd_id int not null auto_increment,
gd_name varchar(50) not null,
gd_use varchar(1) not null,
gd_cash decimal(11,2) not null,
gd_period int not null,
gd_point_save tinyint not null,
primary key (gd_id)
) $default_charset";
$qry = sql_query($sql);

sql_query("alter table {$mw_cash['membership_log_table']} change ml_sdate ml_sdate datetime not null");
sql_query("alter table {$mw_cash['membership_log_table']} change ml_edate ml_edate datetime not null");

sql_query(" update {$mw_cash['membership_log_table']} set ml_edate = FROM_UNIXTIME(unix_timestamp(ml_edate) + 86399, '%Y-%m-%d %H:%i:%s') where right(ml_edate, 8) = '00:00:00' ");

sql_query("alter table {$mw_cash['membership_board_table']} add mp_comment char(1) not null ", false);
sql_query("alter table {$mw_cash['cash_list_table']} add cl_agent varchar(255) not null after cl_ip ", false);

echo "<div style='padding:20px; font-size:15px; font-weight:bold;'>컨텐츠샵 설치완료</div>";

include_once($g4['path']."/tail.sub.php");

